import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.util.HashMap;

/**
 * @author 帅小伙
 * @date 2022/1/3
 * @description
 */
public class Consumer71 {

    // 消费者 需要绑定 正常队列  死信队列  正常交换机  死信交换机
    private static final String NORMAL_EXCHANGE_NAME = "normal_exchange";
    private static final String NORMAL_QUEUE_NAME = "normal_queue";

    private static final String DEAD_EXCHANGE_NAME = "dead_exchange";
    private static final String DEAD_QUEUE_NAME = "dead_queue";

    public void consume() throws Exception {
        Channel channel = RabbitMqUtils.getChannel();

        System.out.println(Thread.currentThread().getName() + "  消费者启动等待消费.........");



        // 死信队列
        channel.queueDeclare(DEAD_QUEUE_NAME, false, false, false, null);
        //死信交换机
        channel.exchangeDeclare(DEAD_EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        //死信队列与死信交换机的绑定关系
        channel.queueBind(DEAD_QUEUE_NAME, DEAD_EXCHANGE_NAME, "lisi");


        //正常队列和死信交换机的绑定关系
        HashMap<String, Object> deadLetterParams = new HashMap<>();
        deadLetterParams.put("x-dead-letter-exchange",DEAD_EXCHANGE_NAME);
        deadLetterParams.put("x-dead-letter-routing-key","lisi");
        deadLetterParams.put("x-max-length",6);


        // 正常队列
        channel.queueDeclare(NORMAL_QUEUE_NAME, false, false, false, deadLetterParams);
        //正常交换机
        channel.exchangeDeclare(NORMAL_EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        // 正常队列与正常交换机的绑定关系
        channel.queueBind(NORMAL_QUEUE_NAME, NORMAL_EXCHANGE_NAME, "zansan");





        //
    }
}
